Public Class AccessFile
    Public Enum FolderType
        CommonAppData
        CommonPrograms
        CommonDocuments
        CommonDesktop
        CommonStartMenu
        CommonPictures
        CommonMusic
        CommonVideo
        CommonFavorites
        CommonStartup
        CommonTemplates
        CommonAdiministrativeTools

        PersonalAppData
        PersonalCookies
        PersonalDesktop
        PersonalFavorites
        PersonalNetHood
        PersonalMyDocuments
        PersonalPrintHood
        PersonalRecent
        PersonalSendTo
        PersonalStartMenu
        PersonalTemplates
        PersonalPrograms
        PersonalStartup
        PersonalLocalSettings
        PersonalLocalAppData
        PersonalCache
        PersonalHistory
        PersonalMyPictures
        PersonalFonts
        PersonalMusic
        PersonalCDBurning
        PersonalVideo
        PersonalAdministrativeTools

        ActiveCommonAppData
        ActivePersonalAppData
        Temp
    End Enum

    Public Function GetSpecialFolder(ByVal Type As FolderType) As String
        Dim filepath As String = ""
        Dim key As String = ""
        Dim RegKey As Microsoft.Win32.RegistryKey = Nothing
        Dim RegPath As Integer = 0
        Dim RegPathList() = { _
            "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", _
            "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", _
            "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", _
            ""}

        Select Case Type
            Case FolderType.CommonAppData
                key = "Common AppData"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonAppData
                key = "Common Programs"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonPrograms
                key = "Common Programs"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonDocuments
                key = "Common Documents"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonDesktop
                key = "Common Desktop"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonStartMenu
                key = "Common Start Menu"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonPictures
                key = "CommonPictures"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonMusic
                key = "CommonMusic"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonVideo
                key = "CommonVideo"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonFavorites
                key = "Common Favorites"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonStartup
                key = "Common Startup"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonTemplates
                key = "Common Templates"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.CommonAdiministrativeTools
                key = "Common Administrative Tools"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
            Case FolderType.PersonalAppData
                key = "AppData"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalCookies
                key = "Cookies"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalDesktop
                key = "Desktop"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalFavorites
                key = "Favorites"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalNetHood
                key = "NetHood"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalMyDocuments
                key = "Personal"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalPrintHood
                key = "PrintHood"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalRecent
                key = "Recent"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalSendTo
                key = "SendTo"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalStartMenu
                key = "Start Menu"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalTemplates
                key = "Templates"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalPrograms
                key = "Programs"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalStartup
                key = "Startup"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalLocalSettings
                key = "Local Settings"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalLocalAppData
                key = "Local AppData"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalCache
                key = "Cache"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalHistory
                key = "History"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalMyPictures
                key = "My Pictures"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalFonts
                key = "Fonts"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalMusic
                key = "My Music"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalCDBurning
                key = "CD Burning"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalVideo
                key = "My Video"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.PersonalAdministrativeTools
                key = "Administrative Tools"
                RegKey = My.Computer.Registry.CurrentUser
                RegPath = 1
            Case FolderType.ActiveCommonAppData
                filepath = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
                RegPath = -1
            Case FolderType.ActivePersonalAppData
                filepath = My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
                RegPath = -1
            Case FolderType.Temp
                filepath = My.Computer.FileSystem.SpecialDirectories.Temp
                RegPath = -1
            Case Else
                key = "Personal"
                RegKey = My.Computer.Registry.LocalMachine
                RegPath = 0
        End Select

        If RegPath >= 0 Then
            filepath = RegKey.OpenSubKey(RegPathList(RegPath)).GetValue(key).ToString
        End If

        Return filepath
    End Function
End Class
